package me.landery.modules.sinco.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import me.landery.base.BaseEntity;
import me.landery.modules.system.domain.User;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Objects;

@Entity
@Getter
@Setter
@Table(name="sinco_app")
public class Application extends BaseEntity {

    @Id
    @Column(name = "id", nullable = false)
    @NotNull(groups = BaseEntity.Update.class)
    @ApiModelProperty(value = "应用表ID", hidden = true)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "uid")
    @ApiModelProperty(value = "用户id")
    private User user;


    @Column(name = "appid",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "应用id")
    private String appid;

    @Column(name = "secretkey",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "接口访问密钥")
    private String secretkey;

    @Column(name = "remark")
    @ApiModelProperty(value = "应用备注")
    private String remark;

    @Column(name = "name")
    @ApiModelProperty(value = "应用名称")
    private String name;

    @Column(name = "status")
    @ApiModelProperty(value = "应用状态0禁用，1启用")
    private Integer status;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Application application = (Application) o;
        return Objects.equals(id, application.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    public void copy(Application source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}
